package com.sigerap.insumo.model.dao.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.sigerap.insumo.model.DetalleSolicitud;
import com.sigerap.insumo.model.Insumo;
import com.sigerap.insumo.model.InsumoProveedor;
import com.sigerap.insumo.model.dao.InsumoDAO;
import com.sigerap.proveedor.model.Proveedor;
/**
 * 
 * @author Spirit-20121
 *
 */
public class JPAInsumoDAO implements InsumoDAO{
	private EntityManager em;
	private Insumo insumo;
	
	public JPAInsumoDAO(EntityManager em){
		this.em = em;
	}
	
	@Override
	public List<Insumo> findAll() {
		Query query = em.createQuery("Select i.nombre From Insumo i ");
		return query.getResultList();
	}

	@Override
	public Insumo findByNombre(Insumo insumo) {
		// TODO Auto-generated method stub
		String nombre=insumo.getNombre();
		insumo=(Insumo)em.createQuery("Select i From Insumo i where i.nombre='"+nombre+"'").getSingleResult();
		return insumo;
	}

	@Override
	public Insumo insert(Insumo i) {
		// TODO Auto-generated method stub
		em.persist(i);
		return i;
	}

	@Override
	public InsumoProveedor insertInsPro(InsumoProveedor ip) {
		// TODO Auto-generated method stub
		
		try {
			em.persist(ip);
			System.out.println("paso try");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return ip;
	}

	@Override
	public DetalleSolicitud insertSolicitud(DetalleSolicitud ds) {
		// TODO Auto-generated method stub
		em.persist(ds);
		return ds;
	}

	

}

	